from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-12 14:07:41.573895
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 12, May, 2021
Time: 14:07:46
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.1756
Nobs: 289.000 HQIC: -48.8599
Log likelihood: 3525.71 FPE: 3.81794e-22
AIC: -49.3174 Det(Omega_mle): 2.81105e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375571 0.114014 3.294 0.001
L1.Burgenland 0.070831 0.058708 1.206 0.228
L1.Kärnten -0.225600 0.052302 -4.313 0.000
L1.Niederösterreich 0.106569 0.124859 0.854 0.393
L1.Oberösterreich 0.224732 0.121873 1.844 0.065
L1.Salzburg 0.281386 0.066915 4.205 0.000
L1.Steiermark 0.108961 0.085579 1.273 0.203
L1.Tirol 0.120829 0.059227 2.040 0.041
L1.Vorarlberg -0.030658 0.054511 -0.562 0.574
L1.Wien -0.025268 0.108692 -0.232 0.816
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.405415 0.131296 3.088 0.002
L1.Burgenland 0.006251 0.067606 0.092 0.926
L1.Kärnten 0.327895 0.060229 5.444 0.000
L1.Niederösterreich 0.119908 0.143784 0.834 0.404
L1.Oberösterreich -0.069933 0.140346 -0.498 0.618
L1.Salzburg 0.231979 0.077058 3.010 0.003
L1.Steiermark 0.091340 0.098550 0.927 0.354
L1.Tirol 0.135537 0.068205 1.987 0.047
L1.Vorarlberg 0.153273 0.062773 2.442 0.015
L1.Wien -0.393446 0.125166 -3.143 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.257112 0.058032 4.431 0.000
L1.Burgenland 0.105569 0.029882 3.533 0.000
L1.Kärnten -0.013041 0.026621 -0.490 0.624
L1.Niederösterreich 0.089252 0.063552 1.404 0.160
L1.Oberösterreich 0.283265 0.062032 4.566 0.000
L1.Salzburg 0.019363 0.034059 0.569 0.570
L1.Steiermark -0.000970 0.043559 -0.022 0.982
L1.Tirol 0.069876 0.030146 2.318 0.020
L1.Vorarlberg 0.076872 0.027745 2.771 0.006
L1.Wien 0.114534 0.055323 2.070 0.038
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194854 0.055272 3.525 0.000
L1.Burgenland 0.027850 0.028460 0.979 0.328
L1.Kärnten 0.009649 0.025355 0.381 0.704
L1.Niederösterreich 0.062921 0.060529 1.040 0.299
L1.Oberösterreich 0.396121 0.059082 6.705 0.000
L1.Salzburg 0.083556 0.032439 2.576 0.010
L1.Steiermark 0.130139 0.041487 3.137 0.002
L1.Tirol 0.051423 0.028712 1.791 0.073
L1.Vorarlberg 0.082570 0.026426 3.125 0.002
L1.Wien -0.040344 0.052692 -0.766 0.444
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.416782 0.108926 3.826 0.000
L1.Burgenland 0.103092 0.056087 1.838 0.066
L1.Kärnten 0.011199 0.049967 0.224 0.823
L1.Niederösterreich 0.045078 0.119286 0.378 0.706
L1.Oberösterreich 0.119012 0.116434 1.022 0.307
L1.Salzburg 0.063467 0.063929 0.993 0.321
L1.Steiermark 0.062782 0.081759 0.768 0.443
L1.Tirol 0.198605 0.056584 3.510 0.000
L1.Vorarlberg 0.040475 0.052078 0.777 0.437
L1.Wien -0.056415 0.103840 -0.543 0.587
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214274 0.085172 2.516 0.012
L1.Burgenland -0.013058 0.043856 -0.298 0.766
L1.Kärnten -0.005181 0.039071 -0.133 0.895
L1.Niederösterreich -0.005193 0.093273 -0.056 0.956
L1.Oberösterreich 0.415534 0.091042 4.564 0.000
L1.Salzburg 0.012622 0.049988 0.253 0.801
L1.Steiermark -0.030876 0.063930 -0.483 0.629
L1.Tirol 0.161935 0.044244 3.660 0.000
L1.Vorarlberg 0.058890 0.040721 1.446 0.148
L1.Wien 0.196832 0.081196 2.424 0.015
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189086 0.104320 1.813 0.070
L1.Burgenland 0.023639 0.053716 0.440 0.660
L1.Kärnten -0.071136 0.047855 -1.487 0.137
L1.Niederösterreich -0.030971 0.114242 -0.271 0.786
L1.Oberösterreich 0.010522 0.111511 0.094 0.925
L1.Salzburg 0.090125 0.061226 1.472 0.141
L1.Steiermark 0.313724 0.078302 4.007 0.000
L1.Tirol 0.455804 0.054191 8.411 0.000
L1.Vorarlberg 0.149258 0.049876 2.993 0.003
L1.Wien -0.128254 0.099450 -1.290 0.197
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201415 0.123403 1.632 0.103
L1.Burgenland 0.041985 0.063542 0.661 0.509
L1.Kärnten -0.073447 0.056609 -1.297 0.194
L1.Niederösterreich 0.115152 0.135140 0.852 0.394
L1.Oberösterreich 0.012966 0.131909 0.098 0.922
L1.Salzburg 0.193689 0.072425 2.674 0.007
L1.Steiermark 0.130544 0.092626 1.409 0.159
L1.Tirol 0.055236 0.064104 0.862 0.389
L1.Vorarlberg 0.107850 0.058999 1.828 0.068
L1.Wien 0.222311 0.117642 1.890 0.059
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.482921 0.069165 6.982 0.000
L1.Burgenland -0.012499 0.035614 -0.351 0.726
L1.Kärnten -0.017943 0.031728 -0.566 0.572
L1.Niederösterreich 0.110658 0.075743 1.461 0.144
L1.Oberösterreich 0.306706 0.073932 4.148 0.000
L1.Salzburg 0.026199 0.040593 0.645 0.519
L1.Steiermark -0.045453 0.051915 -0.876 0.381
L1.Tirol 0.080194 0.035929 2.232 0.026
L1.Vorarlberg 0.104236 0.033068 3.152 0.002
L1.Wien -0.033031 0.065936 -0.501 0.616
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.163928 0.086880 0.169887 0.224366 0.076479 0.089931 0.000468 0.171485
Kärnten 0.163928 1.000000 0.053179 0.215159 0.188664 -0.066457 0.179519 0.022219 0.309569
Niederösterreich 0.086880 0.053179 1.000000 0.239691 0.095814 0.314026 0.143933 0.026194 0.312173
Oberösterreich 0.169887 0.215159 0.239691 1.000000 0.306047 0.261573 0.107402 0.062132 0.145052
Salzburg 0.224366 0.188664 0.095814 0.306047 1.000000 0.151460 0.078167 0.090898 0.036422
Steiermark 0.076479 -0.066457 0.314026 0.261573 0.151460 1.000000 0.096786 0.100515 -0.099439
Tirol 0.089931 0.179519 0.143933 0.107402 0.078167 0.096786 1.000000 0.154019 0.158698
Vorarlberg 0.000468 0.022219 0.026194 0.062132 0.090898 0.100515 0.154019 1.000000 -0.011334
Wien 0.171485 0.309569 0.312173 0.145052 0.036422 -0.099439 0.158698 -0.011334 1.000000